<?php
	include('../../../db.php');
	include("$root/host/model/product_db.php");
	include("$root/host/model/category_db.php");
?>
<div id="controller">
	<div id="add_category">
		<h2>Add Category</h2>
	<form name="add_category" method="POST">
		<div class="input_container">
			<label>Name :</label>
			<input id="category_name" type="text" maxlength="32" name="category_name" required autofocus>
		</div>
		<div id="add_category_submit" class="input_container">
			<input id="add_category_button" class="small" name="button" type="button" value="Add" onClick="addCategory()">
		</div>
	</form>
	</div>
	<div id="add_product">
		<h2>Add Product</h2>
	<form name="add_product" method="POST">
		<div class="input_container">
			<label>Name :</label>
			<input id="product_name" type="text" maxlength="32" name="product_name" required>
		</div>
		<div class="input_container">
			<select id="product_category" name="product_category" required>
				<option selected disabled value="">Category</option>
			<?php
				$categories = getCategories();
				foreach ($categories as $category) {
					?><option value="<?php echo $category['id']?>"><?php echo ucfirst($category['name']) ?></option>
					<?php
				}
			?>
			</select>
		</div>
		<div class="input_container">
			<label>Description :</label>
			<input id="product_description" type="text" name="product_name" required>
		</div>
		<div class="input_container">
			<label>Price :</label>
			<input id="product_price" type="number" min=0 step=0.01 value=0.00 name="product_price" required>
		</div>
		<div id="add_product_submit" class="input_container">
			<input id="add_product_button" class="small" name="button" type="button" value="Add" onClick="addProduct()">
		</div>
	</form>
	</div>
</div>
<div id="product_table">
<?php
	$categories = getCategories();
	foreach ($categories as $category) {
		$products = getProductsFromCategory($category['id']);
		?>  <h2 class="category title"><?php echo strtoupper($category['name']); ?> </h2>
			<table>
			<tr>
				<td>Product</td>
				<td>Description</td>
				<td>Price</td>
				<td>Delete</td>
			</tr>
			<?php
				foreach ($products as $product) {
					?>
					<tr>
					<td class="product name small"><?php echo $product['name']?></td>
					<td class="product description huge"><?php echo $product['description']?></td>
					<td class="product price small"><?php echo $product['price']?></td>
					<td class="product delete tiny"><input id="delete_button" name="button" type="button" value="X" onClick="deleteProduct(<?php echo $product['id']?>)"></td>
					</tr>
					<?php
				}
			?>
			</table>
		<?php
	}
?>
</div>
